/**
 * @file       IEventListener_test.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 13, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "IEventListener.h"
#include "gtest/gtest.h"
#include "errorcode.h"
#include "MockEventListener.h"
#include "MockKeyboardEvent.h"
namespace NS_LCD_AFW
{
class IEventListener_test : public ::testing::Test
{
public:
	virtual void SetUp()
	{
	}
	virtual void TearDown()
	{
	}
};
TEST_F(IEventListener_test,test_defualtConstruction)
{
	CMockEventListener *pListener = new CMockEventListener();
	EXPECT_EQ(NULL,pListener->getEventHandler());
	EXPECT_TRUE(pListener->isAutoReleaae());
	OBJ_DESTORY(pListener);
}
TEST_F(IEventListener_test,test_Construction_2)
{
	CEventHandler *pHandler = new CEventHandler();
	CMockEventListener *pListener = new CMockEventListener(pHandler);
	EXPECT_EQ(pHandler,pListener->getEventHandler());
	EXPECT_TRUE(pListener->isAutoReleaae());
	OBJ_DESTORY(pListener);
	pListener = new CMockEventListener(pHandler,false);
	EXPECT_EQ(pHandler,pListener->getEventHandler());
	EXPECT_FALSE(pListener->isAutoReleaae());
	OBJ_DESTORY(pListener);
	OBJ_DELETE(pHandler);
}
TEST_F(IEventListener_test,test_Construction_3)
{
	CEventHandler *pHandler = new CEventHandler();
	CMockEventListener *pListener = new CMockEventListener(pHandler,123,NULL,-1);
	EXPECT_EQ(pHandler,pListener->getEventHandler());
	EXPECT_TRUE(pListener->isAutoReleaae());
	EXPECT_EQ((AFW_EventCallBack)NULL,pHandler->getCallBack(123));
	OBJ_DESTORY(pListener);
	OBJ_DELETE(pHandler);

	pHandler = new CEventHandler();
	pListener = new CMockEventListener(pHandler,123,NULL,-1,false);
	EXPECT_EQ(pHandler,pListener->getEventHandler());
	EXPECT_EQ((AFW_EventCallBack)NULL,pHandler->getCallBack(123));
	EXPECT_FALSE(pListener->isAutoReleaae());
	OBJ_DESTORY(pListener);
	OBJ_DELETE(pHandler);
}
TEST_F(IEventListener_test,test_getEventHandler)
{
	CEventHandler *pHandler = new CEventHandler();
	CMockEventListener *pListener = new CMockEventListener(pHandler);
	EXPECT_EQ(pHandler, pListener->getEventHandler());
	OBJ_DESTORY(pListener);
	OBJ_DELETE(pHandler);
}
TEST_F(IEventListener_test,test_setEventHandler)
{
	CEventHandler *pHandler = new CEventHandler();
	CMockEventListener *pListener = new CMockEventListener();
	EXPECT_EQ(NULL, pListener->getEventHandler());
	pListener->setEventHandler(pHandler);
	EXPECT_EQ(pHandler, pListener->getEventHandler());
	pListener->setEventHandler(NULL);
	EXPECT_EQ(NULL, pListener->getEventHandler());
	OBJ_DESTORY(pListener);
	OBJ_DELETE(pHandler);
}
TEST_F(IEventListener_test,test_isAutoReleaae)
{
	CMockEventListener *pListener = new CMockEventListener();
	EXPECT_TRUE(pListener->isAutoReleaae());
	pListener->setAutoReleaae(false);
	EXPECT_FALSE(pListener->isAutoReleaae());
	OBJ_DESTORY(pListener);
}
TEST_F(IEventListener_test,test_setAutoReleaae)
{
	CMockEventListener *pListener = new CMockEventListener();
	EXPECT_TRUE(pListener->isAutoReleaae());
	pListener->setAutoReleaae(false);
	EXPECT_FALSE(pListener->isAutoReleaae());
	pListener->setAutoReleaae(true);
	EXPECT_TRUE(pListener->isAutoReleaae());
	OBJ_DESTORY(pListener);
}
TEST_F(IEventListener_test,test_actionPerformed)
{
	CEventHandler *pHandler = new CEventHandler();
	CMockEventListener *pListener = new CMockEventListener();
	IEvent *pEvent = new CMockKeyboardEvent();
	EXPECT_EQ(NULL,pListener->getEventHandler());

	EXPECT_EQ(ERR_INVALID_EVENTHANDLER,pListener->actionPerformed(pEvent));

	pListener->setEventHandler(pHandler);
	EXPECT_EQ(ERR_INVALID_EVENTHANDLER,pListener->actionPerformed(NULL));

	EXPECT_EQ(ERR_INVALID_EVENTHANDLER,pListener->actionPerformed(pEvent));

	OBJ_DESTORY(pListener);
	OBJ_DELETE(pHandler);
	OBJ_DESTORY(pEvent);
}
TEST_F(IEventListener_test,test_destory)
{

}
} /* namespace NS_LCD_AFW */
